package com.lance.answer.gui.answer.gk.video.tmp;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lance.answer.gui.answer.Util;
import com.lance.answer.gui.answer.gk.DealInfoUtil;
import com.lance.answer.gui.answer.gk.video.dto.WatchVideoDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 看所有的章节-小节
 */
@Slf4j
public class WatchAllChapter {

    public static final String JS = "var video = document.getElementsByTagName(\"video\");if(video.length>0){ video[0].src = \"https://jvod.300hu.com/vod/product/a7d50669-f57b-4da9-8cf8-43d04372cab0/0411e189a55b41cfada876041fa7fdd7.mp4?source=2&h265=h265/18799/d7d0ab77577f4ea0bcf5bc794316045a.mp4\";}";


    public static void main(String[] args)  throws Exception{


   //     Thread.sleep(1000*60*60*2);
        //   int sync = 6;
        String driverPath = null;
        int sync = 1;

        List<String> subjectList = Lists.newArrayList();
  //      subjectList.add("公共关系学");
//        subjectList.add("西方行政学说");
//        subjectList.add("计算机应用基础(本)");
//        subjectList.add("公共部门人力资源管理");
//  //      subjectList.add("中国当代文学专题");
    //   subjectList.add("人文英语4"); ok

  //      subjectList.add("监督学");
        subjectList.add("政治学原理");
        subjectList.add("公共行政学");
        subjectList.add("个人与团队管理");
        subjectList.add("办公室管理");
        subjectList.add("人力资源管理");
        subjectList.add("管理英语2");
  //      subjectList.add("社会调查研究与方法");
//       subjectList.add("政府经济学");
  //      subjectList.add("马克思主义基本原理概论"); OK
      //  subjectList.add("现代汉语专题");
      //  subjectList.add("形势与政策");
    //   subjectList.add("人文英语4");


        LinkedBlockingDeque<WatchVideoDto> watchVideoQueue = new LinkedBlockingDeque<>();

        for(String subjectName:subjectList){
            List<String> userNames = DealInfoUtil.countUserCourseInfo("libs//userCourseInfo").get(subjectName);
            InputStream inputStream2 =  new FileInputStream("libs//2022User.txt");
            List<String> userString = IOUtils.readLines(inputStream2, "utf-8");

            Map<String, String> usernameAndPwd = Maps.newHashMap();
            for (String user : userString) {
                String[] strs = user.split(",");
                String userCode = strs[0];
                String pwd = strs[1].substring(6, 14);
                pwd = "Ouchn" + pwd;
                usernameAndPwd.put(userCode, pwd);
            }

            for(String username:userNames){
                if(!Util.getVip().contains(username)){
                    continue;
                }
                String pwd = usernameAndPwd.get(username);
                WatchVideoDto videoDto = new WatchVideoDto();
                videoDto.setUserName(username);
                videoDto.setPassword(pwd);
                videoDto.setSubjectName(subjectName);
                //   videoDto.setSubjectCode(subjectCode);
                videoDto.setJS(JS);
                watchVideoQueue.add(videoDto);
            }

        }


        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new WatchAllChapterTask(driverPath,watchVideoQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName( "答题线程--" + i);
            answerThread.start();
        }

    }



}
